package cn.itcast.config;

import jakarta.annotation.PostConstruct;
import org.springframework.ai.document.Document;
import org.springframework.ai.reader.JsonReader;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
class MyJsonReader {

	private final Resource resource;

    @Autowired
    private VectorStore vectorStore;

    MyJsonReader(@Value("classpath:rule.json") Resource resource) {
        this.resource = resource;
    }

    @PostConstruct
	void loadJsonAsDocuments() {
        JsonReader jsonReader = new JsonReader(this.resource, "description", "content","type");
        List<Document> documents = jsonReader.get();
       this. vectorStore.add( documents);
    }
}